<template>
  <div id="myChart" :style="{width: '800px', height: '600px'}"></div>
</template>

<script>
export default {
  name: "Bar",
  data() {
    return {
      names : null,
      values : null
    }
  },
  mounted(){
    let _this = this
    // 基于准备好的dom，初始化echarts实例
    let myChart = this.$echarts.init(document.getElementById('myChart'))
    axios.get("http://localhost:8081/fruit/bar").then(function (response){
      _this.names = response.data.names
      _this.values = response.data.values
      // 绘制图表
      myChart.setOption({
        title: {
          text: '水果销量统计',
          subtext: '柱状图',
          left: 'center',
          top: 0,
          textStyle: {
            color: '#555555'
          }
        },
        tooltip: {},
        xAxis: {
          data: _this.names
        },
        yAxis: {},
        series: [{
          name: '销量',
          type: 'bar',
          data: _this.values
        }]
      });
    })
  }
}
</script>

<style scoped>

</style>